package lhc.alg.top100;

/**
 * description:  https://leetcode.cn/problems/rotate-array/
 *
 *  这不就旋转数组
 *
 *  找规律 利用翻转
 *
 * author: hongchen.liao
 * date:  2022/8/19
 */
public class _189_Rotate_Array {

    class Solution {
        public void rotate(int[] nums, int k) {
            k %= nums.length;
            reverse(nums, 0, nums.length - 1);
            reverse(nums, 0, k - 1);
            reverse(nums, k, nums.length-1);
        }

        void reverse(int[] nums, int start, int end){
            while(start < end){
                int tmp = nums[start];
                nums[start] = nums[end];
                nums[end] = tmp;
                start += 1;
                end -= 1;
            }
        }
    }


}
